var GameData = require('GameData');
var ObserverMgr = require("ObserverMgr");
cc.Class({
    extends: cc.Component,

    properties: {
        noticeLabel: {default: null, displayName: "公告", type: cc.Label},

    },

    onLoad: function () {
        var str = GameData.data.noticeData.notice;
        if ( str && str.length > 0) {
            this._setNoticeString(str);
            this._runMoveAni();
        }
    },
    _setNoticeString(str){
        this.noticeLabel.string = str;
    },
    _getNextNoticeString(){
        return GameData.data.noticeData.notice;
    },
    onClick(){
        ObserverMgr.dispatchMsg(GameLocalMsg.Center.OnClickAbout, null);
    },
    _runMoveAni(){
        var parent = this.noticeLabel.node.parent;
        var parentWidth = parent.width;
        var selfWidth = this.noticeLabel.node.width;
        var desPosX = -(selfWidth + parentWidth / 2);
        var y = this.noticeLabel.node.y;
        this.noticeLabel.node.x = parentWidth / 2;

        var moveTo = cc.moveTo(10, desPosX, y)
        var delay = cc.delayTime(1);
        var callFunc = cc.callFunc(function () {
            this.noticeLabel.node.x = parentWidth / 2;
            var str = this._getNextNoticeString();
            this._setNoticeString(str);
        }.bind(this), this.noticeLabel.node);
        var seq = cc.sequence([moveTo, delay, callFunc]);
        var repeat = cc.repeatForever(seq);
        this.noticeLabel.node.runAction(repeat);
    },

});
